<?php
/*
 * 注册人数
 * @author  Mark
 * @package ixdcw
 * @file    xcharts.inc.php
 * @time    13-1-10 上午10:29
 */
defined('IN_IXDCW') or exit('Access Denied');
$menus = array (
	array('注册人数', '?file='.$file.'&action=regnum'),
);
$xScales = array(
	'ordinal'     => 'ordinal',
//	'linear'      => 'linear',
//	'time'        => 'time',
//	'exponential' => 'exponential',
);
$yScales = array(
	'exponential' => 'exponential',
	'ordinal'     => 'ordinal',
	'linear'      => 'linear',
	'time'        => 'time',
);
$types = array(
	"bar"         => "bar",
	"cumulative"  => "cumulative",
	"line"        => "line",
	"line-dotted" => "line-dotted",
);

$xScale = (isset($xScale)) ? $xScale : $xScales['ordinal'];
$yScale = (isset($yScale)) ? $yScale : $yScales['exponential'];
$type   = (isset($type)) ? $type : $types['line-dotted'];

$startDate   = (isset($startDate)) ? $startDate : date('Y-m-d', strtotime('-1month', $DT_TIME));

switch($action) {
	case 'regnum':
	default:
		// init
		if (preg_match('/([0-9]{4})\-([0-9]{1,2})\-([0-9]{1,2})/is', $startDate, $matchStartDate)) {
			$timeStart = mktime(0,0,0,$matchStartDate[2],$matchStartDate[3],$matchStartDate[1]);
		} else {
			$timeStart = strtotime('-30days');
		}

		$timeEnd = strtotime('+1month', $timeStart);

		$sql = "select FROM_UNIXTIME(regtime, '%Y-%m-%d') as day, count(*) as cnt
				from {$db->getPre()}member
				where {$timeStart} < regtime and regtime < {$timeEnd}
				group by day
				order by day asc";
		$res = $db->query($sql);
		$result = array();
		$num = 0;
		while ($r = $db->fetchArray($res)) {
			$result[$num]['x'] = $r['day'];
			$result[$num]['y'] = (int) $r['cnt'];
			$num++;
		}
		$data = json_encode($result);

		include tpl('xcharts');
	break;
}